package <%=basePackage%>.service;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.javacc.util.Status;
import <%=basePackage%>.dao.<%=simpleClassName%>Dao;
import <%=className%>;;

@Service
public class <%=simpleClassName%>Service {
	@Inject
    private <%=simpleClassName%>Dao <%=entity%>Dao;

    public <%=simpleClassName%> get<%=simpleClassName%>ById(Long id) {
        <%=simpleClassName%> <%=entity%> =  this.<%=entity%>Dao.get(id);
        if (<%=entity%> != null && <%=entity%>.getStatus() == Status.NORMAL) {
			return <%=entity%>;
		}
		return null;
    }
    
    public List<<%=simpleClassName%>> list<%=simpleClassName%>s(int offset, int fetchSize) {
        return this.<%=entity%>Dao.findAll(offset, fetchSize);
    }
    
    public int get<%=simpleClassName%>TotalSize() {
        return this.<%=entity%>Dao.getTotalSize();
    }

    @Transactional
    public void save<%=simpleClassName%>(<%=simpleClassName%> <%=entity%>) {
        this.<%=entity%>Dao.save(<%=entity%>);
    }

    @Transactional
    public void update<%=simpleClassName%>(<%=simpleClassName%> <%=entity%>) {
        this.<%=entity%>Dao.update(<%=entity%>);
    }

    @Transactional
    public void delete<%=simpleClassName%>(Long id) {
        this.<%=entity%>Dao.delete(id);
    }
}
